<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家优惠券列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">

                <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                <script type="text/html" id="test-table-reload-barDemo">
                    <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/merchant/merchantCouponList')} layui-hide #{/if}" lay-event="edit"><i class="layui-icon layui-icon-set-fill"></i>优惠券配置</a>
                    <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/merchant/subAccountList')} layui-hide #{/if}" lay-event="subAccount">子账号</a>
                </script>
            </div>
        </div>
    </div>
</div>

<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'utils'], function () {
        var $ = layui.$,
                table = layui.table,
                admin = layui.admin;

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            , url: "/merchant/getMerchantList"
            , toolbar: '#test-table-reload-toolbar'
            , defaultToolbar: ['filter']
            , cellMinWidth: 80
            , cols: [[
                {field: 'id', title: '商家ID', fixed: true}
                , {field: 'mobile', title: '商家手机号'}
                , {field: 'name', title: '商家名称'}
                 ,{field: 'couponId', title: '优惠券ID'}
                , {field: 'couponName', title: '优惠券', width: 350}
                , {field: 'createByName', title: '创建人'}
                , {field: 'createTime', title: '创建时间', sort: true, templet: function (d) {
                        return "<div>" + layui.toDateString(d.createTime) + "</div>";
                    }}
                , {fixed: 'right', title: '操作', toolbar: '#test-table-reload-barDemo', width: 200}
            ]]
            , page: true
            , height: 520
        });

        //监听行工具事件
        table.on('tool(test-table-reload)', function (obj) {
            var data = obj.data;
            if (obj.event === 'invalid') {
                layer.confirm('该账号停止使用状态，是否要启用？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4}, function () {
                    $.get("/merchant/updateInValid?id=" + data.id + "&invalid=0", function (result) {
                        if (result.code > 0) {
                            layer.msg(result.msg, {icon: 2});
                        } else {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                window.location.reload();
                            });
                        }
                    });
                });
            } else if (obj.event === 'valid') {
                layer.confirm('该账号正常使用状态，是否要停用？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4}, function () {
                    $.get("/merchant/updateInValid?id=" + data.id + "&invalid=1", function (result) {
                        if (result.code > 0) {
                            layer.msg(result.msg, {icon: 2});
                        } else {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                window.location.reload();
                            });
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                parent.layui.index.openTabsPage("/merchant/merchantCouponList?merchantId=" + data.id + "&merchantName=" + data.name , "<span style= 'color: red'>"+ data.name+ "</span>" +" 的优惠券配置");
            } else if (obj.event === 'subAccount') {
                layer.open({
                    type: 2 //Page层类型
                    , area: ['1200px', '700px']
                    , title: ['<span style="color: red">' + data.name + '</span>' + '的子账号列表']
                    , skin: 'layui-layer-lan'
                    , shade: [0.5, '#393D49']  //遮罩透明度
                    , anim: 1 //0-6的动画形式，-1不开启
                    , content: '/merchant/subAccountList?parentId=' + data.id
                    , btn: ['取消']
                });
            }
        });

    });
</script>
</body>
</html>